package com.sxpro;
import java.time.LocalTime;

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
    }
}

class TemperatureControlSystem {
    enum State {
        IDLE, HEATING, SLEEP, BROKEN, SHUTDOWN
    }

    private State currentState;
    private boolean hasWater;  // 水箱是否有水
    private boolean isHeaterOn;  // 是否正在加热
    private double currentTemperature;  // 当前温度
    private LocalTime currentTime;  // 当前时间

    public TemperatureControlSystem() {
        this.currentState = State.IDLE;
        this.hasWater = false;
        this.isHeaterOn = false;
        this.currentTemperature = 0.0;
        this.currentTime = LocalTime.now();  // 初始化当前时间
    }

    // 模拟温度和水量传感器
    public void setWaterStatus(boolean hasWater) {
        this.hasWater = hasWater;
    }

    public void setTemperature(double temperature) {
        this.currentTemperature = temperature;
    }

    public void setTime(LocalTime time) {
        this.currentTime = time;
    }

    // 模拟主控制过程
    public void controlLoop() {
        while (true) {
            switch (currentState) {
                case IDLE:
                    // 处于空闲状态，等待条件判断
                    checkStartHeating();
                    break;
                case HEATING:
                    // 加热过程中
                    checkTemperatureAndWater();
                    break;
                case SLEEP:
                    // 休眠状态
                    checkSleepTime();
                    break;
                case BROKEN:
                    // 水箱烧坏
                    repair();
                    break;
                case SHUTDOWN:
                    // 停止加热
                    shutdownHeating();
                    break;
            }

            // 为了模拟每次的状态更新，可以适当延时
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    private void checkStartHeating() {
        if (currentTemperature < 20.0 && hasWater) {
            // 温度低于20度且有水时开始加热
            System.out.println("温度低于20°C，开始加热...");
            currentState = State.HEATING;
            isHeaterOn = true;
        } else if (!hasWater) {
            System.out.println("水箱无水，无法加热。");
        }
    }

    private void checkTemperatureAndWater() {
        if (currentTemperature >= 100.0) {
            // 如果水温达到100°C，断开电源
            System.out.println("水温达到100°C，停止加热。");
            currentState = State.SHUTDOWN;
            isHeaterOn = false;
        } else {
            System.out.println("当前温度为：" + currentTemperature + "°C, 继续加热...");
        }
    }

    private void checkSleepTime() {
        // 检查当前时间，如果是晚上11点，则断开电源，进入休眠
        if (currentTime.equals(LocalTime.of(23, 0))) {
            System.out.println("已到晚上11点，进入休眠状态...");
            isHeaterOn = false;
            currentState = State.SLEEP;
        } else if (currentTime.equals(LocalTime.of(7, 0))) {
            System.out.println("早上7点，开始加热...");
            currentState = State.IDLE;
        }
    }

    private void repair() {
        System.out.println("水箱烧坏，需要进行维修...");
        // 假设修理完成后恢复到IDLE状态
        currentState = State.IDLE;
        System.out.println("水箱维修完成，恢复到待机状态。");
    }

    private void shutdownHeating() {
        System.out.println("停止加热，断开电源。");
        isHeaterOn = false;
        currentState = State.IDLE;
    }
}